import random

def guess_number_game():
    number_to_guess = random.randint(1, 20)  # 生成1到20之间的随机数
    attempts = 6  # 设置玩家有6次猜测的机会

    print("欢迎来到猜数字游戏！")
    print("我想了一个1到20之间的数字。")
    print("你有6次机会猜出它是什么。")

    for attempt in range(1, attempts + 1):
        try:
            guess = int(input(f"第{attempt}次尝试：请输入你的猜测（1-20）："))

            if guess < 1 or guess > 20:
                print("猜测数字需要在1到20之间！")
            elif guess < number_to_guess:
                print("不对，太低了！")
            elif guess > number_to_guess:
                print("不对，太高了！")
            else:
                print(f"恭喜！你在第{attempt}次尝试里猜对了！数字正是 {number_to_guess}。")
                break
        except ValueError:
            print("请输入一个有效的数字。")

    if guess != number_to_guess:
        print(f"哦不！你用完了所有的尝试。我想的数字是 {number_to_guess}。")

guess_number_game()